package cn.bone.base.conf;

import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.ErrorPageRegistrar;
import org.springframework.boot.web.server.ErrorPageRegistry;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;

@Configuration
public class ErrorPageConfig {

    @Bean
    public ErrorPageRegistrar containerCustomizer(){
//        return new MyErrorpageRegistrar();

        return registry -> {
            registry.addErrorPages(
                    new ErrorPage(HttpStatus.BAD_REQUEST,"/400"),
                    new ErrorPage(HttpStatus.UNAUTHORIZED, "/401"),
                    new ErrorPage(HttpStatus.PAYMENT_REQUIRED, "/402"),
                    new ErrorPage(HttpStatus.FORBIDDEN, "/403"),
                    new ErrorPage(HttpStatus.NOT_FOUND, "/404")
            );
        };
    }


    private static class MyErrorpageRegistrar implements ErrorPageRegistrar {

        @Override
        public void registerErrorPages(ErrorPageRegistry registry) {
            registry.addErrorPages(
                new ErrorPage(HttpStatus.BAD_REQUEST,"/400"),
                new ErrorPage(HttpStatus.UNAUTHORIZED, "/401"),
                new ErrorPage(HttpStatus.PAYMENT_REQUIRED, "/402"),
                new ErrorPage(HttpStatus.FORBIDDEN, "/403"),
                new ErrorPage(HttpStatus.NOT_FOUND, "/404")
            );

        }
    }
}
